<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Stok_peternakan_model extends CI_Model{

	function get_alasan(){
		return $this->db->select('*')
				->from('alasan_perubahan')
				->order_by("ID_ALASAN_PERUBAHAN")
				->get();
	}
	
	function insert_history($data){
		return $this->db->insert("stok", $data);
	}
	
	function get_data_stok(){
		return $this->db->select("
									stok.ID_STOK,
									titik_pasok.NAMA as PETERNAKAN,
									sapi.NAMA as SAPI,
									user.NAMA as USER,
									alasan_perubahan.NAMA_ALASAN_PERUBAHAN as ALASAN,
									stok.JUMLAH,
									stok.TANGGAL_KEJADIAN,
									stok.KOMENTAR
								")
						->from("stok")
						->join("sapi", "sapi.ID_SAPI=stok.ID_SAPI")
						->join("user", "user.ID_USER=stok.ID_USER")
						->join("alasan_perubahan","alasan_perubahan.ID_ALASAN_PERUBAHAN=stok.ALASAN_PERUBAHAN")
						->join("titik_pasok","titik_pasok.ID_TITIK_PASOK=stok.ID_TITIK_PASOK")
						->order_by("stok.ID_STOK","DESC")
						->get();
						
	}
		
}